/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nc.kyiv.yellow.sociallibrary.beans.bookinfo;

import com.nc.kyiv.yellow.sociallibrary.dao.Book;
import com.nc.kyiv.yellow.sociallibrary.dao.BookDAO;
import java.util.Map;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

/**
 *
 * @author My
 */
public class BookInfoBean implements SessionBean {
    
    private SessionContext context;

    // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">;
    // TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
    // TODO Add business methods or web service operations
    /**
     * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
     */
    public void setSessionContext(SessionContext aContext) {
        context = aContext;
    }

    /**
     * @see javax.ejb.SessionBean#ejbActivate()
     */
    public void ejbActivate() {
        
    }

    /**
     * @see javax.ejb.SessionBean#ejbPassivate()
     */
    public void ejbPassivate() {
        
    }

    /**
     * @see javax.ejb.SessionBean#ejbRemove()
     */
    public void ejbRemove() {
        
    }

    // </editor-fold>;
    /**
     * See section 7.10.3 of the EJB 2.0 specification See section 7.11.3 of the
     * EJB 2.1 specification
     */
    public void ejbCreate() {
        
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method" or "Web Service > Add Operation")
    
    public void addBookInfo(Map params) throws Exception {
        String title = (String) params.get("title");
        title = title.replace("'", "''");
        String description = (String) params.get("description");
        description = description.replace("'", "''");
        
        Book book = new Book(params.get("isbn").toString(), title, description, Integer.valueOf(params.get("numberOfPages").toString()), params.get("image").toString());
        
        BookDAO dao = new BookDAO();
        dao.save(book);
    }
    
}
